var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();

Page({
  data: {
    hotelId: 0,
    hotel: "",
    rooms: [],
    images: [],
    coverImage: "",
    imageNumber: 1,
    notes: [],
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0
  },
  getData: function () {
    let that = this;
    util.request(api.HotelDetail + "/" + that.data.hotelId).then(function (res) {
      if (res.code === '200') {

        that.setData({
          tickets: res.datas.hotelRooms,
          images: res.datas.images,
          hotel: res.datas.hotel,
          notes: res.datas.features,
          coverImage: res.datas.hotel.path,
          imageNumber: res.datas.images.length
        });
        wx.setNavigationBarTitle({
          //页面标题为路由参数
          title: res.datas.hotel.hotelName
        })
      }
    });
  },

  onLoad: function (options) {
    var that = this;

    that.setData({
      hotelId: options.id//options为页面路由过程中传递的参数
    })
    // 页面初始化 options为页面跳转所带来的参数
    this.getData();
    /** 
      * 获取系统信息 
      */
    wx.getSystemInfo({

      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }

    });
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  },
  previewImage: function () {
    var that = this;
    wx.previewImage({
      current: 1, // 当前显示图片的http链接  
      urls: that.data.images// 需要预览的图片http链接列表  
    })
  },
  /** 
     * 滑动切换tab 
     */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });

  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  }

})